home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfbtileodd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  7.0 KB  |  282 lines

  1. /*
  2.  * Fill odd tiled rectangles.  Used by both PolyFillRect and PaintWindow.
  3.  * no depth dependencies.
  4.  */
  5.  
  6. /*
  7. Copyright 1989 by the Massachusetts Institute of Technology
  8.  
  9. Permission to use, copy, modify, and distribute this software and its
  10. documentation for any purpose and without fee is hereby granted,
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in
  13. supporting documentation, and that the name of M.I.T. not be used in
  14. advertising or publicity pertaining to distribution of the software
  15. without specific, written prior permission.  M.I.T. makes no
  16. representations about the suitability of this software for any
  17. purpose.  It is provided "as is" without express or implied warranty.
  18. */
  19.  
  20. /* $XConsortium: cfbtileodd.c,v 1.5 89/12/13 14:34:01 keith Exp $ */
  21.  
  22. #include "X.h"
  23. #include "Xmd.h"
  24. #include "servermd.h"
  25. #include "gcstruct.h"
  26. #include "window.h"
  27. #include "pixmapstr.h"
  28. #include "scrnintstr.h"
  29. #include "windowstr.h"
  30.  
  31. #include "cfb.h"
  32. #include "cfbmskbits.h"
  33. #include "cfb8bit.h"
  34.  
  35. #define LastTileBits {\
  36.     tmp = bits; \
  37.     if (tileEndPart) \
  38.     bits = (*pSrc & tileEndMask) | BitRight (*pSrcLine, tileEndLeftShift); \
  39.     else \
  40.     bits = *pSrc; \
  41. }
  42.  
  43. #define ResetTileBits {\
  44.     pSrc = pSrcLine; \
  45.     nlwSrc = widthSrc;\
  46.     if (tileEndPart) { \
  47.     if (PPW - xoff + tileEndPart <= PPW) {\
  48.         bits = *pSrc++; \
  49.         nlwSrc--; \
  50.     } else \
  51.         bits = BitLeft(tmp, tileEndLeftShift) | \
  52.            BitRight(bits, tileEndRightShift); \
  53.     xoff = (xoff + xoffStep) & PIM; \
  54.     leftShift = xoff << (5-PWSH); \
  55.     rightShift = 32 - leftShift; \
  56.     }\
  57. }
  58.  
  59. #define NextTileBits {\
  60.     if (nlwSrc == 1) {\
  61.     LastTileBits\
  62.     } else { \
  63.         if (nlwSrc == 0) {\
  64.         ResetTileBits\
  65.         } \
  66.     tmp = bits; \
  67.     bits = *pSrc++; \
  68.     }\
  69.     nlwSrc--; \
  70. }
  71.  
  72. void
  73. cfbFillBoxTileOdd (pDrawable, nBox, pBox, tile, xrot, yrot)
  74.     DrawablePtr        pDrawable;
  75.     int            nBox;    /* number of boxes to fill */
  76.     register BoxPtr pBox;    /* pointer to list of boxes to fill */
  77.     PixmapPtr        tile;    /* tile */
  78.     int            xrot, yrot;
  79. {
  80.     int tileWidth;    /* width of tile in pixels */
  81.     int tileHeight;    /* height of the tile */
  82.     int widthSrc;
  83.  
  84.     int widthDst;        /* width in longwords of the dest pixmap */
  85.     int w;        /* width of current box */
  86.     int h;        /* height of current box */
  87.     unsigned long startmask;
  88.     unsigned long endmask;    /* masks for reggedy bits at either end of line */
  89.     int nlwMiddle;    /* number of longwords between sides of boxes */
  90.     int nlwSrc;        /* number of whole longwords in source */
  91.     
  92.     register int nlw;    /* loop version of nlwMiddle */
  93.     int srcy;        /* current tile y position */
  94.     int srcx;        /* current tile x position */
  95.     int xoffDst, xoffSrc;
  96.     int leftShift, rightShift;
  97.  
  98.     unsigned long *pDstBase;    /* pointer to start of dest */
  99.     unsigned long *pDstLine;    /* poitner to start of dest box */
  100.     unsigned long *pSrcBase;    /* pointer to start of source */
  101.     unsigned long *pSrcLine;    /* pointer to start of source line */
  102.     register unsigned long *pDst;
  103.     register unsigned long *pSrc;
  104.     register unsigned long bits, tmp;
  105.     int xoffStart, xoff;
  106.     int leftShiftStart, rightShiftStart, nlwSrcStart;
  107.     unsigned long tileEndMask;
  108.     int tileEndLeftShift, tileEndRightShift;
  109.     int    xoffStep;
  110.     int tileEndPart;
  111.     int needFirst;
  112.     unsigned long   narrow[2];
  113.     unsigned long   narrowMask;
  114.     int        narrowShift;
  115.     Bool    narrowTile;
  116.  
  117.     tileHeight = tile->drawable.height;
  118.     tileWidth = tile->drawable.width;
  119.     widthSrc = tile->devKind >> 2;
  120.     narrowTile = FALSE;
  121.     if (widthSrc == 1)
  122.     {
  123.     narrowShift = tileWidth;
  124.     narrowMask = cfbendpartial [tileWidth];
  125.     tileWidth *= 2;
  126.     widthSrc = 2;
  127.     narrowTile = TRUE;
  128.     }
  129.     pSrcBase = (unsigned long *)tile->devPrivate.ptr;
  130.  
  131.     if (pDrawable->type == DRAWABLE_WINDOW)
  132.     {
  133.     pDstBase = (unsigned long *)
  134.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  135.     widthDst = (int)
  136.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  137.     }
  138.     else
  139.     {
  140.     pDstBase = (unsigned long *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  141.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  142.     }
  143.  
  144.     tileEndPart = tileWidth & PIM;
  145.     tileEndMask = cfbendpartial[tileEndPart];
  146.     tileEndLeftShift = (tileEndPart) << (5-PWSH);
  147.     tileEndRightShift = 32 - tileEndLeftShift;
  148.     xoffStep = PPW - tileEndPart;
  149.     /*
  150.      * current assumptions: tile > 32 bits wide.
  151.      */
  152.     while (nBox--)
  153.     {
  154.     w = pBox->x2 - pBox->x1;
  155.     h = pBox->y2 - pBox->y1;
  156.     srcx = (pBox->x1 - xrot) % tileWidth;
  157.     srcy = (pBox->y1 - yrot) % tileHeight;
  158.     xoffDst = pBox->x1 & PIM;
  159.     if (xoffDst + w < PPW)
  160.     {
  161.         maskpartialbits(pBox->x1, w, startmask);
  162.         endmask = 0;
  163.         nlwMiddle = 0;
  164.     }
  165.     else
  166.     {
  167.         maskbits (pBox->x1, w, startmask, endmask, nlwMiddle)
  168.     }
  169.     pDstLine = pDstBase + (pBox->y1 * widthDst) + (pBox->x1 >> PWSH);
  170.     pSrcLine = pSrcBase + (srcy * widthSrc);
  171.     xoffSrc = srcx & PIM;
  172.     if (xoffSrc >= xoffDst)
  173.     {
  174.         xoffStart = xoffSrc - xoffDst;
  175.         needFirst = 1;
  176.     }
  177.     else
  178.     {
  179.         xoffStart = PPW - (xoffDst - xoffSrc);
  180.         needFirst = 0;
  181.     }
  182.     leftShiftStart = (xoffStart) << (5-PWSH);
  183.     rightShiftStart = 32 - leftShiftStart;
  184.     nlwSrcStart = widthSrc - (srcx >> PWSH);
  185.     while (h--)
  186.     {
  187.         /* XXX only works when narrowShift >= PPW/2 */
  188.         if (narrowTile)
  189.         {
  190.         tmp = pSrcLine[0] & narrowMask;
  191.         narrow[0] = tmp | SCRRIGHT (tmp, narrowShift);
  192.         narrow[1] = SCRLEFT (tmp, PPW - narrowShift) |
  193.                 SCRRIGHT(tmp, 2 * narrowShift - PPW);
  194.         pSrcLine = narrow;
  195.         }
  196.         xoff = xoffStart;
  197.         leftShift = leftShiftStart;
  198.         rightShift = rightShiftStart;
  199.         nlwSrc = nlwSrcStart;
  200.         pSrc = pSrcLine + (srcx >> PWSH);
  201.         pDst = pDstLine;
  202.         bits = 0;
  203.         if (needFirst)
  204.         {
  205.         NextTileBits
  206.         }
  207.         if (startmask)
  208.         {
  209.         NextTileBits
  210.         tmp = BitLeft(tmp, leftShift);
  211.          if (rightShift != 32)
  212.             tmp |= BitRight(bits,rightShift);
  213.         *pDst = *pDst & ~startmask | tmp & startmask;
  214.         ++pDst;
  215.         }
  216.         nlw = nlwMiddle;
  217.         if (tileEndPart)
  218.         {
  219.             while (nlw--)
  220.             {
  221.             NextTileBits
  222.             if (rightShift != 32)
  223.                 *pDst++ = BitLeft(tmp, leftShift) |
  224.                         BitRight(bits, rightShift);
  225.             else
  226.                 *pDst++ = tmp;
  227.             }
  228.         }
  229.         else
  230.         {
  231.         if (leftShift)
  232.         {
  233.             while (nlw--)
  234.             {
  235.                 if (nlwSrc == 0)
  236.                 {
  237.                 nlwSrc = widthSrc;
  238.                 pSrc = pSrcLine;
  239.                 }
  240.                 tmp = bits;
  241.                 bits = *pSrc++;
  242.             nlwSrc--;
  243.             *pDst++ = BitLeft(tmp, leftShift) |
  244.                   BitRight(bits, rightShift);
  245.             }
  246.         }
  247.         else
  248.         {
  249.             while (nlw--)
  250.             {
  251.                 if (nlwSrc == 0)
  252.                 {
  253.                 nlwSrc = widthSrc;
  254.                 pSrc = pSrcLine;
  255.                 }
  256.             *pDst++ = bits;
  257.                 bits = *pSrc++;
  258.             nlwSrc--;
  259.             }
  260.         }
  261.         }
  262.         if (endmask)
  263.         {
  264.         NextTileBits
  265.         if (rightShift == 32)
  266.             bits = 0;
  267.         *pDst = *pDst & ~endmask |
  268.              (BitLeft(tmp, leftShift) |
  269.               BitRight(bits,rightShift)) & endmask;
  270.         }
  271.         pDstLine += widthDst;
  272.         pSrcLine += widthSrc;
  273.         if (++srcy == tileHeight)
  274.         {
  275.         srcy = 0;
  276.         pSrcLine = pSrcBase;
  277.         }
  278.     }
  279.     pBox++;
  280.     }
  281. }
  282.